package com.zhangliuliu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhangliuliu.bean.ExpertBean;
import com.zhangliuliu.dao.ExpertDao;
import com.zhangliuliu.service.ExpertService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class ExpertServiceImpl extends ServiceImpl<ExpertDao, ExpertBean>implements ExpertService {
    @Override
    public void addExpert(ExpertBean expertBean) {
        save(expertBean);
    }

    @Override
    public ExpertBean getOne(int id) {
      QueryWrapper wrapper = new QueryWrapper();
      wrapper.eq("pk_id",id);
       return this.getOne(wrapper);

    }

    @Override
    public void updateExpert(int id, String tell, String post, String unit, String mail) {
         ExpertBean expertBean = new ExpertBean();
         expertBean.setExId(id);
         expertBean.setTell(tell);
         expertBean.setPost(post);
         expertBean.setUnit(unit);
         expertBean.setMail(mail);
        this.updateById(expertBean);
    }

    @Override
    public void delExpert(int id) {
        removeById(id);

    }

    @Override
    public IPage<ExpertBean> cutByItem(int pageNo, int pageSize, String name, String good, String unit) {
    Page<ExpertBean> Page = new Page<>(pageNo, pageSize);
       QueryWrapper wrapper = new QueryWrapper();
       if (name!=null&&!name.equals("")){
           wrapper.eq("expert_name",name);
       }
       if (good!=null&&!name.equals("")){
           wrapper.eq("expert_goods",good);
       }
       if (unit!=null&&!unit.equals("")){
           wrapper.eq("expert_unit",unit);
       }
        IPage<ExpertBean> page = this.page(Page, wrapper);
       return page;
    }

    @Override
    public void del(int id) {
        removeById(id);
    }
}
